package com.yh.patterns.Strategy.job;

import java.util.Random;

/**
 * @Author:云尚
 * @Description:
 */
public class ContextPwd {
    private StrategyPassWord strategyPassWord;
    public ContextPwd(StrategyPassWord strategyPassWord) {
        this.strategyPassWord = strategyPassWord;
    }
    //展示给用户加密后的密码
    public void show(){
        strategyPassWord.encryption();
        System.out.println("密码加密成功,加密后的密码为："+getCharAndNumr(6));
    }
    public String getCharAndNumr(int length) {
        Random random = new Random();
        StringBuffer valSb = new StringBuffer();
        String charStr = "0123456789abcdefghijklmnopqrstuvwxyz";
        int charLength = charStr.length();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(charLength);
            valSb.append(charStr.charAt(index));
        }
        return valSb.toString();
    }
}
